package udf.string;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;

import udf.matching.MultiWordFeatureGenerator;

public class Permutations {

	/**
	 * @param args
	 */
	
	
	public static HashSet<String> permutations(LinkedList<String> tags){

		HashSet<String> list = new HashSet<String>();

		//sorts ascending
		Collections.sort(tags, String.CASE_INSENSITIVE_ORDER);
		
		for(int i =2; i <tags.size()+1; i++){

			list.addAll(permutations(tags,i));
			
		}
		
		

		return list;
		
	} 
	
	
	public static LinkedList<String> permutations(LinkedList<String> tags, int size){
		
	LinkedList<String >permu= new LinkedList<String>();
		for(int i =0; i< tags.size()-1; i++){
		
			for(int j=i+1; j< tags.size(); j++){
				StringBuffer combi = new StringBuffer();
				combi.append(tags.get(i));
				//String combi= tags.get(i);
				
				for(int k=1; k<size && j + k-1 <tags.size(); k++){
					combi.append("_"+ tags.get(k+j-1));
					//combi = combi  + "_"+ tags.get(k+j-1);
					
				}
				
				String combi_ =  new String(combi.toString());
				if(combi_.contains("_") && !tags.contains(combi_)){
					
					permu.add(combi_);
				}
				
				combi =null;
			}
			
		}
		
		return permu;
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
LinkedList<String> tags = new LinkedList<String>();
		
		//tags.add("e");
		tags.add("c");
		tags.add("b");
		tags.add("a");
		tags.add("d");
		
	
		HashSet<String> perm = Permutations.permutations(tags);
	
		
		
		Iterator<String> iter = perm.iterator();
		
		while(iter.hasNext()){
			
			System.out.println(iter.next());
		}
		
		
		
	}

}
